// module name: encoder
// description: N-n encoder
// author: yangtao2019
// date: 2021.07.11

`timescale 1ns / 1ps

module encoder
#(
    parameter n = 5,
    parameter N = (2<<n)
)
(
    input [N-1:0] paths,
    output reg [n-1:0] addr
);

// inputs are assumed to be at-most-on-hot code
always @ (*) begin: Nn_encoder
    integer i;
    for (i=0; i<N; i=i+1) begin
        if (paths[i] == 1'b1) begin
            addr = i;
        end
    end
end

endmodule